package cn.cs.service.impl;

import cn.cs.client.CommonFailuresClient;
import cn.cs.common.Constants;
import cn.cs.common.EmptyUtils;
import cn.cs.common.Page;
import cn.cs.pojo.CommonFailures;
import cn.cs.service.CommonFailuresService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class CommonFailuresServiceImpl implements CommonFailuresService {

    @Resource
    private CommonFailuresClient commonFailuresClient;

    public CommonFailures getCommonFailuresById(String id) throws Exception {
        return commonFailuresClient.getCommonFailuresById(id);
    }

    public List<CommonFailures> getCommonFailuresListByMap(Map<String, Object> param) throws Exception {
        return commonFailuresClient.getCommonFailuresListByMap(param);
    }

    public Integer getCommonFailuresCountByMap(Map<String, Object> param) throws Exception {
        return commonFailuresClient.getCommonFailuresCountByMap(param);
    }

    public Integer addCommonFailures(CommonFailures commonFailures) throws Exception {
        commonFailures.setCreateDate(new Date());
        return commonFailuresClient.addCommonFailures(commonFailures);
    }

    public Integer modifyCommonFailures(CommonFailures commonFailures) throws Exception {
        commonFailures.setModifyDate(new Date());
        return commonFailuresClient.modifyCommonFailures(commonFailures);
    }

    public Integer deleteCommonFailuresById(String id) throws Exception {
        return commonFailuresClient.deleteCommonFailuresById(id);
    }

    public Page<CommonFailures> queryCommonFailuresPageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) throws Exception {
        Integer total = commonFailuresClient.getCommonFailuresCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<CommonFailures> commonFailuresList = commonFailuresClient.getCommonFailuresListByMap(param);
        page.setRows(commonFailuresList);
        return page;
    }

}
